home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / ghostscript / src / gscie.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  7KB  |  223 lines

  1. /* Copyright (C) 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gscie.h */
  20. /* Structures for Ghostscript CIE color algorithms */
  21. /* (requires gscspace.h, gscolor2.h, gxrefct.h)
  22.  
  23. /* ------ Common definitions ------ */
  24.  
  25. /* A 3-element vector. */
  26. typedef struct gs_vector3_s {
  27.     float u, v, w;
  28. } gs_vector3;
  29.  
  30. /* A 3x3 matrix, stored in column order. */
  31. typedef struct gs_matrix3_s {
  32.     gs_vector3 cu, cv, cw;
  33.     int is_identity;
  34. } gs_matrix3;
  35.  
  36. /* A 3-element vector of ranges. */
  37. typedef struct gs_range_s {
  38.     float rmin, rmax;
  39. } gs_range;
  40. typedef struct gs_range3_s {
  41.     gs_range u, v, w;
  42. } gs_range3;
  43.  
  44. /* Client-supplied transformation procedures. */
  45. struct gs_cie_common_s;
  46. typedef struct gs_cie_common_s gs_cie_common;
  47. struct gs_cie_wbsd_s;
  48. typedef struct gs_cie_wbsd_s gs_cie_wbsd;
  49. typedef int (*gs_cie_a_proc)(P3(const float *,
  50.   const gs_cie_a *, float *));
  51. typedef int (*gs_cie_abc_proc3)(P3(const gs_vector3 *,
  52.   const gs_cie_abc *, gs_vector3 *));
  53. typedef int (*gs_cie_common_proc3)(P3(const gs_vector3 *,
  54.   const gs_cie_common *, gs_vector3 *));
  55. typedef int (*gs_cie_render_proc3)(P3(const gs_vector3 *,
  56.   const gs_cie_render *, gs_vector3 *));
  57. typedef int (*gs_cie_transform_proc3)(P4(const gs_vector3 *,
  58.   const gs_cie_wbsd *, const gs_cie_render *, gs_vector3 *));
  59. typedef int (*gs_cie_render_table_proc)(P4(const byte *, int,
  60.   const gs_cie_render *, float *));
  61.  
  62. /* CIE white and black points. */
  63. typedef struct gs_cie_wb_s {
  64.     gs_vector3 WhitePoint;
  65.     gs_vector3 BlackPoint;
  66. } gs_cie_wb;
  67.  
  68. /* ------ Caches ------ */
  69.  
  70. /*
  71.  * Given that all the client-supplied procedures involved in CIE color
  72.  * mapping and rendering are monotonic, and given that we can determine
  73.  * the minimum and maximum input values for them, we can cache their values.
  74.  * This takes quite a lot of space, but eliminates the need for callbacks
  75.  * deep in the graphics code (particularly the image operator).
  76.  *
  77.  * The procedures, and how we determine their domains, are as follows:
  78.  
  79. Stage        Name        Domain determination
  80. -----        ----        --------------------
  81. color space    DecodeA        RangeA
  82. color space    DecodeABC    RangeABC
  83. color space    DecodeLMN    RangeLMN
  84. rendering    TransformPQR    RangePQR
  85.   (but depends on color space White/BlackPoints)
  86. rendering    EncodeLMN    RangePQR transformed by the inverse of
  87.                   MatrixPQR and then by MatrixLMN
  88. rendering    EncodeABC    RangeLMN transformed by MatrixABC
  89. rendering    RenderTable.T    [0..1]*m
  90.  
  91.  * Note that we can mostly cache the results of the color space procedures
  92.  * without knowing the color rendering parameters, and vice versa,
  93.  * because of the range parameters supplied in the dictionaries.
  94.  * We suspect it's no accident that Adobe specified things this way.  :-)
  95.  * Unfortunately, TransformPQR is an exception.
  96.  *
  97.  * If we wish, we can often cache the values as fracs rather than floats,
  98.  * when we can determine the range as well as the domain.  We don't
  99.  * do this currently, because it's extra work for a modest space payoff.
  100.  */
  101.  
  102. /* The index into a cache is (value - base) * factor, where */
  103. /* factor is computed as (cie_cache_size - 1) / (rmax - rmin). */
  104. #define gx_cie_log2_cache_size 8
  105. #define gx_cie_cache_size (1 << gx_cie_log2_cache_size)
  106. typedef struct gx_cie_cache_s {
  107.     float base, factor;
  108.     float values[gx_cie_cache_size];
  109.     int is_identity;
  110. } gx_cie_cache;
  111. #if gx_cie_log2_cache_size < 8
  112. #  define gx_cie_byte_to_cache_index(b)\
  113.      ((b) >> (8 - gx_cie_log2_cache_size))
  114. #else
  115. #  if gx_cie_log2_cache_size > 8
  116. #    define gx_cie_byte_to_cache_index(b)\
  117.        (((b) << (gx_cie_log2_cache_size - 8)) +\
  118.         ((b) >> (16 - gx_cie_log2_cache_size)))
  119. #  else
  120. #    define gx_cie_byte_to_cache_index(b) (b)
  121. #  endif
  122. #endif
  123.  
  124. /* ------ Color space dictionaries ------ */
  125.  
  126. /* Elements common to ABC and A dictionaries. */
  127. struct gs_cie_common_s {
  128.     gs_range3 RangeLMN;
  129.     gs_cie_common_proc3 DecodeLMN;
  130.     gs_matrix3 MatrixLMN;
  131.     gs_cie_wb points;
  132.         /* Following are computed when structure is initialized. */
  133.     struct {
  134.         gx_cie_cache DecodeLMN[3];
  135.     } caches;
  136. };
  137.  
  138. /* A CIEBasedABC dictionary. */
  139. struct gs_cie_abc_s {
  140.     gs_cie_common common;        /* must be first */
  141.     rc_header rc;
  142.     gs_range3 RangeABC;
  143.     gs_cie_abc_proc3 DecodeABC;
  144.     gs_matrix3 MatrixABC;
  145.         /* Following are computed when structure is initialized. */
  146.     struct {
  147.         gx_cie_cache DecodeABC[3];
  148.     } caches;
  149. };
  150.  
  151. /* A CIEBasedA dictionary. */
  152. struct gs_cie_a_s {
  153.     gs_cie_common common;        /* must be first */
  154.     rc_header rc;
  155.     gs_range RangeA;
  156.     gs_cie_a_proc DecodeA;
  157.     gs_vector3 MatrixA;
  158.         /* Following are computed when structure is initialized. */
  159.     struct {
  160.         gx_cie_cache DecodeA;
  161.     } caches;
  162. };
  163.  
  164. /* Default values for components */
  165. extern const gs_range3 Range3_default;
  166. extern const gs_cie_abc_proc3 DecodeABC_default;
  167. extern const gs_cie_common_proc3 DecodeLMN_default;
  168. extern const gs_matrix3 Matrix3_default;
  169. extern const gs_range RangeA_default;
  170. extern const gs_cie_a_proc DecodeA_default;
  171. extern const gs_vector3 MatrixA_default;
  172. extern const gs_vector3 BlackPoint_default;
  173. extern const gs_cie_render_proc3 Encode_default;
  174. extern const gs_cie_transform_proc3 TransformPQR_default;
  175. extern const gs_cie_render_table_proc RenderTableT_default;
  176.  
  177. /* ------ Rendering dictionaries ------ */
  178.  
  179. struct gs_cie_wbsd_s {
  180.     struct { gs_vector3 xyz, pqr; } ws, bs, wd, bd;
  181. };
  182. typedef struct gs_cie_render_table_s {
  183.     int NA, NB, NC;            /* >1 */
  184.     const byte **table;        /* [NA][m * NB * NC] */
  185.                     /* 0 means no table */
  186.     int m;                /* 3 or 4 */
  187.     gs_cie_render_table_proc T;    /* takes byte[m], returns float[m] */
  188. } gs_cie_render_table;
  189. /* The main dictionary */
  190. struct gs_cie_render_s {
  191.     rc_header rc;
  192.     gs_matrix3 MatrixLMN;
  193.     gs_cie_render_proc3 EncodeLMN;
  194.     gs_range3 RangeLMN;
  195.     gs_matrix3 MatrixABC;
  196.     gs_cie_render_proc3 EncodeABC;
  197.     gs_range3 RangeABC;
  198.     gs_cie_wb points;
  199.     gs_matrix3 MatrixPQR;
  200.     gs_range3 RangePQR;
  201.     gs_cie_transform_proc3 TransformPQR;
  202.     gs_cie_render_table RenderTable;
  203.         /* Following are computed when structure is initialized. */
  204.     gs_matrix3 MatrixPQR_inverse_LMN;
  205.     gs_vector3 wdpqr, bdpqr;
  206.     struct {
  207.         gx_cie_cache EncodeLMN[3];
  208.         gx_cie_cache EncodeABC[3];
  209.         gx_cie_cache RenderTableT[4];
  210.     } caches;
  211. };
  212.  
  213. /* ------ Joint caches ------ */
  214.  
  215. /* This cache depends on both the color space and the rendering */
  216. /* dictionary -- see above. */
  217.  
  218. typedef struct gx_cie_joint_caches_s {
  219.     rc_header rc;
  220.     gs_cie_wbsd points_sd;
  221.     gx_cie_cache TransformPQR[3];
  222. } gx_cie_joint_caches;
  223.